package com.study.security.core.validate.code.impl.sms.generator;

import com.study.security.core.properties.SecurityProperties;
import com.study.security.core.validate.code.impl.sms.entity.SmsCode;
import com.study.security.core.validate.code.entity.ValidateCode;
import com.study.security.core.validate.code.generator.ValidateCodeGenerator;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * @author LiYongKui
 * @version 1.0
 * @date 2021/4/1 10:57
 */
@Component("smsValidateCodeGenerator")
public class SmsValidateCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public ValidateCode generate(ServletWebRequest request) throws Exception {
        String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
        return new SmsCode(code,securityProperties.getCode().getSms().getExpireIn());
    }
}
